local unit_attribute = require 'types.unit_attribute'
local register = unit_attribute.register



--绿字属性处理
local attrs = {'攻击','护甲','魔抗','力量','敏捷','智力'}
for i,name in ipairs(attrs) do
    local base = ('基础%s'):format(name)
    local exsx = ('额外%s'):format(name)
    local rate = ('%s加成'):format(name)
    

    --总属性
    register(name,{
        on_get = function(self)
            return self:get(base) + self:get(exsx)
        end,
    })

    --基础
    register(base,{
        get = function(self)
            return 0
        end,
        set = function(self,value, old_value)
            if name=='力量' or name=='敏捷' or name=='智力' then
                self:notify('英雄-三维变动',self,name,value - old_value)
            end

            --额外变动
            self:add(exsx,0)
        end,
    })

    --额外
    register(exsx,{
        on_get = function(self,value)
            return self:get(base) * self:get(rate) / 100 + value
        end,
        set = function(self,value,old_value)
            if name=='力量' or name=='敏捷' or name=='智力' then
                self:notify('英雄-三维变动',self,name,value - old_value)
            end
        end
    })

    --加成
    register(rate,{
        set = function(self,value)
            self:add(exsx,0)
        end
    })
    
end


register('攻击力',{
    get = function(self,change)
        return self:get('攻击')
    end,
})

register('杀敌全属性',{
    on_set = function(self,change)
        self:add('杀敌力量',change)
        self:add('杀敌敏捷',change)
        self:add('杀敌智力',change)
    end,
})


register('全属性加成',{
    on_set = function(self,change)
        self:add('力量加成',change)
        self:add('敏捷加成',change)
        self:add('智力加成',change)
    end,
})

register('每秒属性',{
    on_set = function(self,change)
        self:add('每秒力量',change)
        self:add('每秒敏捷',change)
        self:add('每秒智力',change)
    end,
})

register('生命上限',{
    on_get = function(self,value)
        return value * (1 + self:get('生命加成') / 100)
    end,
})

register('生命加成',{
    on_set = function(self,value)
        local rate = self:get '当前生命百分比' / 100
        return function()
            self:set('生命', self:get '生命上限' * rate)
        end
    end,
})


register('分裂攻击')
register('分裂范围')
register('每秒金币')
register('每秒木材')
register('每秒杀敌')

register('多重伤害',30)
register('弹射伤害',30)

register('免费刷新',1)
register('复活时间',8)

register('力量成长',5)
register('敏捷成长',5)
register('智力成长',5)

register('主属性',{
    set = function(self,value,old_value)
        local old_class = self:get_data('修改前主属性')
        local now_class = ('基础%s'):format(self.main_attribute)
        if old_class then
            self:add(old_class,-old_value)
        end
        self:add(now_class,value)
        self:set_data('修改前主属性',now_class)
    end,
    on_get = function(self)
        return self:get(self.main_attribute)
    end
})


register('主属性成长',{
    set = function(self,value,old_value)
        local old_class = self:get_data('主属性成长类型')
        local now_class = ('%s成长'):format(self.main_attribute)
        if old_class then
            self:add(old_class,-old_value)
        end
        self:add(now_class,value)
        self:set_data('主属性成长类型',now_class)
    end,
})



register('冷却缩减',{
    on_get = function(self)
        local a = math.max(math.min(self:get('冷却速度'),400),20)
        return a/(1 + a*0.01)
    end
})

register('暴击几率')
register('暴击伤害',200)

register('物理易伤')
register('魔法易伤')

register('自适应固伤')
register('自适应伤害')


register('金币',{
    on_set = function(self,change)
        self.owner:add('金币',change)
    end,
})

register('木头',{
    on_set = function(self,change)
        self.owner:add('木材',change)
    end,
})

register('杀敌数',{
    on_set = function(self,change)
        self.owner:add('杀敌',change)
    end,
})

register('杀敌挑战怪数量')
register('金币挑战怪数量')
register('经验挑战怪数量')
register('探索挑战怪数量')
register('英雄刷新次数',2)
